﻿package mortal.game.view.DoubleElevenCollectExchange
{
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.view.CollectExchange.cellRender.*;
    import mortal.game.view.common.*;
    import mortal.game.view.signUp.view.*;

    public class DoubleElevenCollectExchangePanel extends SignUpViewBase
    {
        private var _collectionGiftList:GTileList;
        private var _selectedGiftIndex:int;
        private var _isCreateChildren:Boolean;

        public function DoubleElevenCollectExchangePanel()
        {
            return;
        }// end function

        private function onResLoadCompl() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            this._isCreateChildren = true;
            this.pushUIToDisposeVec(UIFactory.bg(2, 4, 686, 182, this, ImagesConst.collectExchangeBg1));
            this.pushUIToDisposeVec(UIFactory.bg(0, 189, 690, 358, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(90005), 30 + 187, 130 + 18, 600, 200, this, GlobalStyle.textFormatBai.setLeading(1).setSize(14), true));
            this._collectionGiftList = UIFactory.tileList(0, 192, 670 + 20, 360, this);
            this._collectionGiftList.rowHeight = 87;
            this._collectionGiftList.columnWidth = 688;
            this._collectionGiftList.horizontalGap = 0;
            this._collectionGiftList.verticalGap = 0;
            this._collectionGiftList.setStyle("cellRenderer", CollectExchangeCellRender);
            this.initGiftList();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.collectExchange, this.onResLoadCompl);
            return;
        }// end function

        private function initGiftList() : void
        {
            this._collectionGiftList.dataProvider = this.getCollectionGiftListDataProvider();
            this._collectionGiftList.drawNow();
            this._collectionGiftList.verticalScrollBar.x = 675;
            this._collectionGiftList.scrollToIndex(this._selectedGiftIndex);
            return;
        }// end function

        private function getCollectionGiftListDataProvider() : DataProvider
        {
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.collectReward.exchangeGroups;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                if (DoubleElevenCollectExchangeUtil.isDoubleElevenRecipe(_loc_2[_loc_3]))
                {
                    _loc_1.addItem(_loc_2[_loc_3]);
                    if (this._selectedGiftIndex <= 0)
                    {
                        if (_loc_2[_loc_3].isSatisfyRecipe())
                        {
                            this._selectedGiftIndex = _loc_3;
                        }
                    }
                }
                _loc_3++;
            }
            return _loc_1;
        }// end function

        public function refresh(param1:Boolean = false) : void
        {
            if (this._isCreateChildren)
            {
                this._collectionGiftList.dataProvider = this.getCollectionGiftListDataProvider();
                this._collectionGiftList.drawNow();
                this._collectionGiftList.verticalScrollBar.x = 675;
                this._collectionGiftList.scrollToIndex(this._selectedGiftIndex);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            LoaderHelp.removeResEvent(ResFileConst.collectExchange, this.onResLoadCompl);
            if (!this._isCreateChildren)
            {
                return;
            }
            this._isCreateChildren = false;
            this._collectionGiftList.dispose(param1);
            this._collectionGiftList = null;
            this._selectedGiftIndex = 0;
            return;
        }// end function

    }
}
